package haoyc.config;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Memory
 * @version 1.0
 * @date 2021/11/23
 */
public class SessionManagement {

    private final static Map<String, Channel> nameTochannel = new ConcurrentHashMap<>();
    private final static Map<Channel, String> channelToname = new ConcurrentHashMap<>();

    public static Channel getChannel(String name) {
        return nameTochannel.get(name);
    }

    public static void setChannel(String ip, Channel channel) {
        nameTochannel.put(ip, channel);
        channelToname.put(channel, ip);
    }

    private final static Map<Channel, Channel> clientToController = new ConcurrentHashMap<>();
    private final static Map<Channel, Channel> controllerToClient = new ConcurrentHashMap<>();

    public static void bind(Channel ClientChannel, Channel ControllerChannel) {
        clientToController.put(ClientChannel, ControllerChannel);
        controllerToClient.put(ControllerChannel, ClientChannel);
    }

    public static Channel getClientChannel(Channel ControllerChannel) {
        return controllerToClient.get(ControllerChannel);
    }

    public static Channel getControllerChannel(Channel ClientChannel) {
        return clientToController.get(ClientChannel);
    }

}
